Code sample Home

Retrieve drawing's preview image from a file
void DemoGetPreviewImage ()
{
  WCHAR*  szDrwFileName = L"C:/Data/Drawings/Harry_test.lcd";
  WCHAR*  szImgFileName = L"C:/Data/Drawings/Harry_test.bmp";
  bool    bSaveToFile = true;
  int     nBytes, BmpW, BmpH;
  BYTE*   pMem;
  HDC     hWinDC;
  HBITMAP hBmp;
  FILE*   df;
  BITMAPFILEHEADER* pbfh;
  BITMAPINFOHEADER* pbih;
  BITMAPINFO*       pbi;
  BYTE*             pBits;

  // get image size (bytes)
  nBytes = lcGetDrwPreview( szDrwFileName, NULL );
  if (nBytes > 0){
    // allocate memory
    pMem = (BYTE*)malloc( nBytes );
    if (pMem){
      nBytes = lcGetDrwPreview( szDrwFileName, pMem );
      if (bSaveToFile){
        // save image into a file (BMP format)
        df = _wfopen( szImgFileName, L"wb" );
        if (df){
          fwrite( pMem, 1, nBytes, df );
          fclose( df );
        }
      }else{
        // create HBITMAP object
        pbfh  = (BITMAPFILEHEADER*)pMem;
        pbih  = (BITMAPINFOHEADER*)(pMem+14);
        pbi   = (BITMAPINFO*)(pMem+14);
        pBits = pMem + pbfh->bfOffBits;
        BmpW  = pbih->biWidth;
        BmpH  = pbih->biHeight;
        hWinDC = ::GetWindowDC( NULL );
        hBmp = ::CreateDIBitmap( hWinDC, pbih, CBM_INIT, pBits, pbi, DIB_RGB_COLORS );
      }
    }
    free( pMem );
  }
}